﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;

namespace LibNiconico.NiconicoApi.PlayerStatus
{
    public sealed partial class NicoPlayerStatus
    {
        /// <summary>
        /// プレイヤーステータス内部クラス
        /// </summary>
        public sealed partial class InternalClasses
        {
            /// <summary>
            /// メッセージサーバ
            /// </summary>
            public sealed class MessageServer
            {
                /// <summary>
                /// アドレス
                /// </summary>
                public string Addr { get; private set; }

                /// <summary>
                /// ポート番号
                /// </summary>
                public int Port { get; private set; }

                /// <summary>
                /// スレッド番号
                /// </summary>
                public long Thread { get; private set; }

                internal static MessageServer Parse(XElement element)
                {
                    MessageServer server = XElementExtention.Parse(element, "ms", item =>
                    {
                        return new MessageServer
                        {
                            Addr = XElementExtention.GetElementAsString(item, "addr"),
                            Port = XElementExtention.GetElementAsInt(item, "port"),
                            Thread = XElementExtention.GetElementAsLong(item, "thread")
                        };
                    });

                    return server == null ? new MessageServer() : server;
                }

                internal MessageServer() 
                {
                    this.Addr = "";
                    this.Port = 0;
                    this.Thread = 0;
                }
            }
        }
    }

}
